package com.caifu.controller.baseData;

import com.caifu.controller.AbstractController;
import com.caifu.pojo.SysUser;
import com.caifu.pojo.YlFloor;
import com.caifu.service.IFloorService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/baseData/floor")
public class FloorController extends AbstractController {
    @Autowired
    private IFloorService floorService;

    /**
     *
     *功能描述：楼层信息列表
     *
     * @Author  GZ
     * @Date   2020/11/8 10:03
     */
    @RequestMapping("floorList")
    public String buildingList(String buildingNo, Model model){
        try {
            //查询楼苑信息
            JSONObject buildInfo = floorService
                    .queryBuildingInfo(buildingNo);
            model.addAttribute("buildInfo",buildInfo);
            return "baseData/floorList";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     *
     * 功能描述：查询楼层数据信息
     *
     * @Author  GZ
     * @Date   2020/11/8 10:04
     */
    @RequestMapping("obtainFloorData")
    @ResponseBody
    public JSONObject obtainFloorData(String buildingNo){
        try {
            return floorService.queryFloorDate(buildingNo);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     *
     * 功能描述：保存楼层信息
     *
     * @Author  GZ
     * @Date   2020/11/8 11:46
     */
    @RequestMapping("saveFloorInfo")
    @ResponseBody
    public JSONObject saveFloorInfo(YlFloor floor){
        try {
            SysUser user =getUser();
            return floorService.saveFloorInfo(floor,user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     *
     * 功能描述：查询楼层信息
     *
     * @Author  GZ
     * @Date   2020/11/8 11:46
     */
    @RequestMapping("queryFloorInfo")
    @ResponseBody
    public JSONObject queryFloorInfo(String floorNo){
        JSONObject object = new JSONObject();
        try {
            YlFloor floor = floorService.queryFloorInfo(floorNo);
            if(null!=floor){
                object.put("name",floor.getFloorName());
                object.put("use",floor.getFloorUse());
                object.put("floorNo",floor.getFloorNo());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return object;
    }
    /**
     *
     * 功能描述：修改楼层信息
     *
     * @Author  GZ
     * @Date   2020/11/8 11:49
     */
    @RequestMapping("updateFloorInfo")
    @ResponseBody
    public JSONObject updateFloorInfo(YlFloor floor){
        try {
            return floorService.updateFloorInfo(floor);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     *
     * 功能描述：修改楼层信息
     *
     * @Author  GZ
     * @Date   2020/11/8 11:49
     */
    @RequestMapping("deleteFloorInfo")
    @ResponseBody
    public JSONObject deleteFloorInfo(String floorNo){
        try {
            return floorService.deleteFloorInfo(floorNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
